package com.gwsdk.paysdk.floatview;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.gwsdk.open.PayCallback;
import com.gwsdk.paysdk.R;
import com.gwsdk.paysdk.bean.GWPayModel;
import com.gwsdk.paysdk.bean.GWRoomSeatModel;
import com.gwsdk.paysdk.entity.UserLogin;
import com.gwsdk.paysdk.utils.AppStatusManager;
import com.gwsdk.paysdk.utils.GWInflaterUtils;
import com.gwsdk.paysdk.view.RoundCornerImageView;


public class RoomSeatView extends RelativeLayout {

    private View view;
    private RoundCornerImageView iv_user_portrait;
    private ImageView iv_seat_status;
    private TextView seat_index;
    private GWRoomSeatModel seatInfo;

    public RoomSeatView(Context context) {
        super(context);
        initView(context);
    }

    public RoomSeatView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public RoomSeatView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public RoomSeatView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    private void initView(Context context){
        view = LayoutInflater.from(context).inflate(GWInflaterUtils.getLayout(context,"gw_layout_room_seat_view"),this,true);
        iv_user_portrait = view.findViewById(GWInflaterUtils.getControl(context,"iv_user_portrait"));
        iv_user_portrait.setCornerRadius(15);
        iv_seat_status = view.findViewById(GWInflaterUtils.getControl(context,"iv_seat_status"));
        seat_index = view.findViewById(GWInflaterUtils.getControl(context,"seat_index"));
        setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                UserLogin userLogin = AppStatusManager.appStatusManager.userLogin;
                String userId = userLogin.getVoice_id()+"";
                if (seatInfo.isSeat){
                    if (!userId.equals(seatInfo.user_id)){
                        GWPayModel.Instance().payFriend(getContext(), seatInfo, new PayCallback() {
                            @Override
                            public void callback(String result) {

                            }
                        });
                    }
                }

            }
        });
    }

    public void setSeatInfo(GWRoomSeatModel seatInfo) {
        this.seatInfo = seatInfo;

        if (seatInfo.isSeat){
            iv_seat_status.setVisibility(GONE);
            seat_index.setText(seatInfo.nickname);
            Glide.with(getContext()).load(seatInfo.head_picture).into(iv_user_portrait);

        }else {
            seat_index.setText("暂无队友");
            iv_seat_status.setVisibility(VISIBLE);

//            iv_seat_status.setImageResource(GWInflaterUtils.getDrawable(getContext(),"ic_seat_status_enter"));
//            iv_user_portrait.setImageResource(GWInflaterUtils.getDrawable(getContext(),"bg_seat_status"));
            iv_seat_status.setImageResource(R.drawable.ic_seat_status_enter);
            iv_user_portrait.setImageResource(R.drawable.bg_seat_status);
        }
    }
}
